 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SplitContainer Demo</title>
     <style type="text/css">
            @import "../dojo/dojo-release-1.0.0/dijit/themes/tundra/tundra.css";
            @import "../dojo/dojo-release-1.0.0/dojo/resources/dojo.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/tundraGrid.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/Grid.css";
   .titleclass{font-size:12pt;font-weight:bolder;text-align:center}
  #grid { 
			
			width: 40em;
			height: 50em;
		}

		.myFolder{
			display: "block";
			width: 16px;
			height: 16px;
			background: blue;
		}

		.myItem{
			display: "block";
			width: 16px;
			height: 16px;
			background: green;

		}
			
        </style>
        <script type="text/javascript" src="../dojo/dojo-release-1.0.0/dojo/dojo.js"
                djConfig="parseOnLoad: true, isDebug: true,locale: 'zh-cn', extraLocale: ['zh-TW', 'fr']"></script>
 <script>
    
            dojo.require("dojo.data.ItemFileWriteStore");
            dojo.require("dijit.layout.SplitContainer");
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.Tree");
            dojo.require("dojo.parser");
            dojo.require("dijit._tree.dndSource");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.Button");
            dojo.require("dojox.grid.Grid");
            dojo.require("dojox.grid._data.model");
            dojo.require("dojo.i18n");
            dojo.require("dojox.validate._base");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.TextBox");
            dojo.require("dijit.form.FilteringSelect");
            dojo.require("dojox.grid._data.dijitEditors");
            </script>
        
<script type="text/javascript" src="../js/soapclient.js">
        </script>
<script type="text/javascript" >


         var data =new Array();
         var areadata =new Array();
         var placedata = [[false,"","","",""]];
         var querydata = new Array();
         var citydata = new Array();
         var cityareadata = new Array();
         var poptarts ={ label:'name',identifier:'eId',items:data};
         var popStore = new dojo.data.ItemFileWriteStore({data: poptarts});
          //按钮  
          var deletedata =new Array();
          var adddata =new Array();
          var updata =new Array();
          var validateData=new Array();
          //var itemt="区域";
          var identity=0;
          var selectNode;
          
          //验证方法
                      var formatNotNull = function(inDatum,inRowIndex){
           //aler
                 return dojox.validate.isText(inDatum, {minlength: 1}) ? inDatum : "<p style={color:red}> can not is null! </p>";
      		     
		      	}   
          
          
          model = new dojox.grid.data.Table(null, placedata);
          var layout =[{type: 'dojox.GridRowView', width: '20px' },{
                       
                        cells: [
                                [
                                 { name: '选择', width: 3, styles: 'text-align: center;', editor: dojox.grid.editors.Bool },
                                 //{ name: 'no', width: 2, get: function(inRowIndex){ return inRowIndex+1;} },
                                 {name: '名称', width: 20,editor: dojox.grid.editors.Input ,formatter:formatNotNull},
                                 {name: '邮编', width: 10, editor: dojox.grid.editors.Input,formatter:formatNotNull},
                                 {name: '备注', width: 20, editor: dojox.grid.editors.Input,formatter:formatNotNull},
                                 {name: '类型', width: 10, field: 4,editor: dojox.grid.editors.Select,options: [ "区域", "省", "城市", "城区", "街道", "地址" ]}
                                ]
                              ]
                        }];
                        
          //初始查询结果列表
                queryModel = new dojox.grid.data.Table(null, querydata);
         var querylayout =[{type: 'dojox.GridRowView', width: '20px' },{
                       
                        cells: [
                                [
                                 { name: '选择', width: 3, styles: 'text-align: center;',editor: dojox.grid.editors.Bool },
                                 //{ name: 'no', width: 2, get: function(inRowIndex){ return inRowIndex+1;} },
                                 {name: '名称', width: 20},
                                 {name: '邮编', width: 10},
                                 {name: '备注', width: 20},
                                 {name: '类型', width: 10}
                                ]
                              ]
                        }];                 
                        
                     
                           
       	    
	
          //保存列表
                   
          addRow = function(){
          	gridWidget.addRow([false,"","","","",0],gridWidget.model.getRowCount());
	         	gridWidget.updateRow();
	         } 
	         
          function call_funUpd() {
           var s = gridWidget.selection.getSelected();
            var url = "http://localhost:8080/logistics-ws/services/BasicManageService";
           
           for(var i=0;i<s.length;i++){
           var ii=s[i];
           var thisCell=gridWidget.model.data[ii];
           
             var padd = new SOAPClientParameters2();
            
             var placevo=new Object();
             placevo.id=thisCell[5];
             if(dojox.validate.isText(thisCell[1], {minlength: 1})){
              placevo.placeName=thisCell[1];
             }else{
             continue;
             }
              if(dojox.validate.isText(thisCell[2], {minlength: 1})){
             placevo.postCode=thisCell[2];}else{
             continue;
             }
             if(dojox.validate.isText(thisCell[4], {minlength: 1})){
             placevo.placeType=thisCell[4];
             }else{
               continue;
               }
              //if(dojox.validate.isText(thisCell[1], {minlength: 1})){
             placevo.parentPlaceId=identity; 
             /*}else{
             continue;
             }*/
             // if(dojox.validate.isText(thisCell[1], {minlength: 1})){
             placevo.trafficeGrade='1';
             /*}else{
             continue;
             }*/
              if(dojox.validate.isText(thisCell[3], {minlength: 1})){
             placevo.remark=thisCell[3];}else{
             continue;
             }
            
          if(thisCell[5]==0){//新增的记录
                   /*
                  Random rd = new Random();
                  flowInfo.wzFlowID = WZConstants.PREFIX_PLAN_FLOW + System.currentTimeMillis()+flowInfo.hashCode()+rd.nextInt();
                  */
                padd.add('WlPlaceVO',placevo);
                SOAPClient.invoke(url, "createPlace", padd, false,  function GetEnu_callBack(ul, soapResponse){
                if(placevo.placeType!='地址'){
                addTreeNode(selectNode,placevo.placeName,placevo.placeType,ul);
                }
                gridWidget.model.setDatum(ul,i,5);
                });
          }else{//修改的记录
                             
                padd.add('WlPlaceVO',placevo);
                SOAPClient.invoke(url, "updatePlace", padd, false,  function GetEnu_callBack(ul, soapResponse){
                if(placevo.placeType!='地址'){
                setTreeNode(placevo.id,placevo.placeName,placevo.placeType);
                }
                });
             }
		       //
          }
          
          //提交删除的记录？
              for(var i=0;i<deletedata.length;i++){
                   var pdel = new SOAPClientParameters();      
                   pdel.add('id',deletedata[i]);
                   SOAPClient.invoke(url, "deletePlaces", pdel, false,  function GetEnu_callBack(ul, soapResponse){
                   delTreeNode(deletedata[i]);
                });
              }
              gridWidget.updateRow();
              deletedata=new Array();
              
              
           }
          
          
          function removeSelectedRows(){
           var s = gridWidget.selection.getSelected();
           for(var i=0;i<s.length;i++){ 
             var ii=s[i];
             var thisCell=gridWidget.model.data[ii];
             if(thisCell[5]!=0){//要删除的记录
               deletedata.splice(deletedata.length,0,thisCell[5]);
             }
           }    
           gridWidget.removeSelectedRows();
           gridWidget.updateRow();
          
          }   
           
           //添加树节点
         function addTreeNode(pid,placeName,placeType,id){
               
               var pInfo = {
                        					parent: pid.item,		
                        					attribute: "children"	
                        				};
               popStore.newItem({name: placeName,type:placeType ,eId:id}, pInfo);
              
         }  
         
         
         function delTreeNode(id){
               	var node = dijit.byId("tree")._itemNodeMap[id];
                popStore.deleteItem(node.item);//同时删除所有子节点
              }  
              
          function setTreeNode(id,placeName,placeType){
               	var node = dijit.byId("tree")._itemNodeMap[id];
               	popStore.setValue(node.item,"placeName",placeName);         
                popStore.setValue(node.item,"placeType",placeType);      
                node.setLabelNode(placeName);
                 }  
           
        
          
        
           
         function init(){
         
           dojo.connect(gridWidget, "doStartEdit", function(inCell, inRowIndex){
           
            });  
            //单击查询列表里的记录，可选中树中的相应节点
                dojo.connect(queryGrid, "onRowClick", function(e){
                var chickId=queryGrid.model.data[e.rowIndex][5];
                var node = dijit.byId("tree")._itemNodeMap[chickId];
                if(node){
                dijit.byId("tree").focusNode(node);
                }else{
                
                
                }
            });  
        
             dojo.connect(gridWidget.model, "onSelected", function(e){
                    //alert("c3="+e);
                  
            });                       
         
         
             //添加区域结点
                
                var url = "http://localhost:8080/logistics-ws/services/BasicManageService";
                var pl = new SOAPClientParameters();
                pl.add('type','区域') ;
                SOAPClient.invoke(url, "getPlacevoByPlaceType", pl, false,  function GetEnu_callBack(ul, soapResponse){
                  var pInfo = {
                        					parent: null,		
                        					attribute: "children"	
                        				};
                    for(var i = 0; i < ul.length; i++){		
                                 var ulo=ul[i];
                                 popStore.newItem({name: ulo["ns:placeName"],type:ulo["ns:placeType"] ,eId:ulo["ns:id"]}, pInfo);
                                 var items = new Array();
                                  items[0] = false;
                                  items[1] = ulo["ns:placeName"];
                                  items[2] = ulo["ns:postCode"];
                                  items[3] = ulo["ns:remark"];
                                  items[5] = ulo["ns:id"];
                                  items[4] = ulo["ns:placeType"];
                                  placedata[i]=items;
                            }
                    model.setData(placedata);    
                     
               });
                       
                      
            //添加省份结点
            var chitem;
            var chdata =new Array();
            var _tree=dijit.byId("tree");
            var childrenArray1=_tree.getChildren();
            
            for (var i=0; i<childrenArray1.length; i++){//begin	
                var p2 = new SOAPClientParameters();
                
                var chNode =childrenArray1[i];
                chitem=chNode.item;
                var p2Info = {	parent: chitem,		
			                         	attribute: "children"	
			                       };
			    
                p2.add('parentPlaceId',chitem.eId) ;
                SOAPClient.invoke(url, "getPlacevoByParentPlaceId", p2 ,false,  function GetEnu_callBack(ul1, soapResponse){  
                    
                    for(var ii = 0; ii < ul1.length; ii++){	   
                                      var ulo=ul1[ii];
                                     var newItemCity=	popStore.newItem({name: ulo["ns:placeName"],type:ulo["ns:placeType"] ,eId:ulo["ns:id"]}, p2Info);
                                     	//------
                                                   
                                                     var p3 = new SOAPClientParameters();
                                                     var p3Info = {
                                                                    parent: newItemCity,		
                                                                    attribute: "children"	
                                                                   };
                                                    p3.add('parentPlaceId',ulo["ns:id"]) ;
                                                    SOAPClient.invoke(url, "getPlacevoByParentPlaceId", p3 ,false,  function GetEnu_callBack(ul2, soapResponse){  
                                                    for(var j = 0; j < ul2.length; j++){
                                                            var uloo=ul2[j];		
                                                            popStore.newItem( {name: uloo["ns:placeName"],type:uloo["ns:placeType"] ,eId:uloo["ns:id"]}, p3Info);
                                                     }});
                                                    
                                     	//----------
                        }
                   });
                  _tree._expandNode(chNode);
                
                }//end
                
                
               
           
                 
                 
                 //添加城市、城区结点
             dojo.connect(dijit.byId("tree"), "_onExpandoClick", function(message){
                       // _expandNode
                       var node = message.node;
                       var ch2node=node.getChildren();
                       // alert("erwer==="+ch2node.length);
                       for (var i=0; i<ch2node.length; i++){	//BEGIN
                       //alert(ch2node[i].getChildren().length);
                       if(ch2node[i].getChildren().length==0){
                         var ch2item =ch2node[i].item;
                        
                         var p3 = new SOAPClientParameters();
                         var p3Info = {
                                        parent: ch2item,		
                                        attribute: "children"	
                                       };
                        p3.add('parentPlaceId',ch2item["eId"]) ;
                        SOAPClient.invoke(url, "getPlacevoByParentPlaceId", p3 ,false,  function GetEnu_callBack(ul2, soapResponse){  
                            
                            for(var j = 0; j < ul2.length; j++){
                                var ulo=ul2[j];		
                                 if(ulo["ns:placeType"]!='地址'){
                                popStore.newItem( {name: ulo["ns:placeName"],type:ulo["ns:placeType"] ,eId:ulo["ns:id"]}, p3Info);
                         }}});
                         }
                      
                      }//END
             	 
            });
 
                  
            
            
           //查询列表----begin
             dojo.connect(_tree, "onClick", function(item,node){
                    placedata = new Array();
                    selectNode=node;
                    identity = _tree.store.getIdentity(item);
                    var url0 = "http://localhost:8080/logistics-ws/services/BasicManageService";
                    var p0 = new SOAPClientParameters();
                    p0.add('parentPlaceId',item["eId"]) ;
                    
                SOAPClient.invoke(url0, "getPlacevoByParentPlaceId", p0, false,  function GetEnu_callBack(ul, soapResponse){   
                   
                     for(var i = 0; i < ul.length; i++){		
                      var items = new Array();
                      var ulo=ul[i];
                        items[0] = false;
                        items[1] = ulo["ns:placeName"];
                        items[2] = ulo["ns:postCode"];
                        items[3] = ulo["ns:remark"];
                        items[5] = ulo["ns:id"];
                        items[4] = ulo["ns:placeType"];
                        placedata[i]=items;
                    }                
                });       
                model.setData(placedata);
                gridWidget.selection.clear();
                
                
                
                var titles=node.item["name"];
                var parentNodes=node;
              
                while(parentNodes.getParent()!= null&& parentNodes.getParent()["id"]!="tree"){
                      parentNodes=parentNodes.getParent();
                      titles=parentNodes.item["name"]+' '+titles;
                };
              	dojo.byId("placetitle").innerHTML = titles +"";
                deletedata =new Array();                       
                                     
                                     });  
            //查询列表----end
          }//END INIT
            
           dojo.addOnLoad(init);
           

          //查询按钮          
          
          function querybutton(){
          
              var url = "http://localhost:8080/logistics-ws/services/BasicManageService";
              var p = new SOAPClientParameters();
              p.add('placeName','%'+queryname.getDisplayedValue()+'%') ;
              p.add('postCode','%'+querypostcode.getDisplayedValue()+'%') ;
              p.add('placeType','%'+querytype.getDisplayedValue()+'%') ;
              p.add('remark','%'+queryremark.getDisplayedValue()+'%') ;
                   
                SOAPClient.invoke(url, "getPlaceVO", p, false,  function GetEnu_callBack(ul, soapResponse){   
                     querydata=new Array();        
                     for(var i = 0; i < ul.length; i++){		
                      var items = new Array();
                      var ulo=ul[i];
                        items[0] = false;
                        items[1] = ulo["ns:placeName"];
                        items[2] = ulo["ns:postCode"];
                        items[3] = ulo["ns:remark"];
                        items[4] = ulo["ns:placeType"];
                        items[5] = ulo["ns:id"];
                      querydata[i]=items;
                    }                
                });       
                queryModel.setData(querydata); 
          
          }
           
          function  autoaddbutton(){
          
          
          }
           
           
           
             
</script>
</head>
<body class="tundra">
       
	
	 <div dojoType="dijit.layout.SplitContainer"
                orientation="horizontal"
                sizerWidth="7"
                activeSizing="true"
               class ="split1" id="split1"
	             	style="border: 1px solid #bfbfbf;width: 1250px; height: 800px; align:center "  >
		
                <div dojoType="dijit.layout.ContentPane" id="treePane"  sizeMin="20" sizeShare="20"  onDownloadEnd="end" onLoad="myonDownloadEnd" >
                     <script>
              var myonDownloadEnd=function(e){
                               document.split1.style.width=screen.availWidth; 
document.split1.style.height=screen.availHeight;
                      //alert(document.split1.style.width);
                                                      };
              var end=function(e){
               document.split1.style.width=screen.availWidth; 
document.split1.style.height=screen.availHeight;
                      //alert(document.split1.style.width);
      };
            
            
            </script>
                         <div id="tree"  class="container" dojoType="dijit.Tree" persist="false" store="popStore"   labelAttr="name"  childrenAttr="children"  ></div> 
                </div>
                
                <div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50"  >

   <div id="mainTabContainer" dojoType="dijit.layout.TabContainer"  styles="width: 100%; height: 100%;"  >
        
      <div id="queryDiv" dojoType="dijit.layout.ContentPane" title="查询"  >
      <table align="center" width=100% >
      <tr><td>请输入查询条件：</td><td></td></tr>
          <tr><td>名称：<input type="text" jsId="queryname"   dojoType="dijit.form.TextBox"  /></td>
      
         <td> 邮编：<input type="text" jsId="querypostcode"    dojoType="dijit.form.ValidationTextBox"  regExp="\d{0,6}"     invalidMessage="邮编应为不超过六位的阿拉伯数字"></td>
          </tr><tr><td>备注：<input type="text" jsId="queryremark"   dojoType="dijit.form.TextBox"  /></td>
          <td>类型：<select dojoType="dijit.form.FilteringSelect"  jsId="querytype" autocomplete="false" >
                <option value=""></option>
                <option value="区域">区域</option>
                <option value="省" >省</option>
                <option value="城市" >城市</option>
                <option value="城区" >城区</option>
                <option value="街道" >街道</option>
                <option value="地址" >地址</option>
          </select></td></tr>
          </table>
          <div align="center">
          <button dojoType="dijit.form.Button" onclick="querybutton()"> 查询 </button>&nbsp;&nbsp;&nbsp;
          <button dojoType="dijit.form.Button" onclick="autoaddbutton()">智能添加</button>  
          </div>  
           <p><p><p>
          <div id="queryGrid" dojoType="dojox.Grid" jsId="queryGrid" style="{width:100%;height:630px}"	model="queryModel" structure="querylayout"  >
           
           
           </div>
      </div>
      <div id="LittleRed" dojoType="dijit.layout.ContentPane" title="地点"; selected="true" style="width: 100%; height:100%" onLoad="placeonload"  onDownloadStart="onDownloadStartl">
      <script>
            var placeonload=function(e){
              alert("1");
                              };
              var onDownloadStartl=function(e){
              alert("2");
                              };
            </script>
        <div class="titleclass" id="placetitle"></div>
        <div id="gridWidget"  dojoType="dojox.Grid"  style="{width:100%;height:700px}"	jsId="gridWidget"	model="model" structure="Layout" singleClickEdit="true"  ></div>
        <div id="rowCount"></div>
        <div align="center">
         <button dojoType="dijit.form.Button" onclick="addRow()"> 新 增 </button>&nbsp;&nbsp;&nbsp;
         <button dojoType="dijit.form.Button" onclick="removeSelectedRows()">删 除</button>  
         <button dojoType="dijit.form.Button" onclick="call_funUpd()">保 存</button>&nbsp;&nbsp;&nbsp;
         
         </div>   
      </div>
      
     
      
</div>

                       
                </div>
        </div>
</body></html>
